package org.jbit.news.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//import org.jbit.news.dao.UserDao;
import org.jbit.news.dao.impl.UserDaoImpl;
import org.jbit.news.entity.User;
//import org.jbit.news.listener.OnlineUser;

public class UserServlet extends HttpServlet {

	@Override
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		String userName = request.getParameter("uname");
		String password = request.getParameter("upwd");
		User user =new UserDaoImpl().findUser(userName, password);
//		OnlineUser onlineTarget =new OnlineUser();
		
//		onlineTarget.setUser(user);
		if ("admin".equals(userName) && "admin".equals(password)) {
			request.getSession().setAttribute("loginUser", userName);
			response.sendRedirect(request.getContextPath()+"/newspages/admin.jsp");
		}else {
			response.sendRedirect(request.getContextPath()+"/index.jsp");
		}

	}

}
